/**
 * 时间戳转 yyyy-MM-dd
 *
 * @param value
 * @returns {string}
 */
export function timestampToDate(value: Date = new Date()) {
    let date = new Date(value);
    let y: number = date.getFullYear(),
        m: number | string = date.getMonth() + 1,
        d: number | string = date.getDate(),
        h: number | string = date.getHours(),
        i: number | string = date.getMinutes(),
        s: number | string = date.getSeconds();
    if (m < 10) {
        m = '0' + m;
    }
    if (d < 10) {
        d = '0' + d;
    }
    if (h < 10) {
        h = '0' + h;
    }
    if (i < 10) {
        i = '0' + i;
    }
    if (s < 10) {
        s = '0' + s;
    }
    return y + '-' + m + '-' + d;
}

export function timestampToDateTime(value: Date = new Date()) {
    let date = new Date(value);
    let y: number = date.getFullYear(),
        m: number | string = date.getMonth() + 1,
        d: number | string = date.getDate(),
        h: number | string = date.getHours(),
        i: number | string = date.getMinutes(),
        s: number | string = date.getSeconds();
    if (m < 10) {
        m = '0' + m;
    }
    if (d < 10) {
        d = '0' + d;
    }
    if (h < 10) {
        h = '0' + h;
    }
    if (i < 10) {
        i = '0' + i;
    }
    if (s < 10) {
        s = '0' + s;
    }
    return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}

export function timestampToDateTime24(value: Date = new Date()) {
    let date = new Date(value);
    let y: number = date.getFullYear(),
        m: number | string = date.getMonth() + 1,
        d: number | string = date.getDate()

    if (m < 10) {
        m = '0' + m;
    }
    if (d < 10) {
        d = '0' + d;
    }

    return y + '-' + m + '-' + d + ' ' + '23:59:59';
}

export function timestampToMonthTime(value: Date = new Date()) {
    let date = new Date(value);
    let y: number = date.getFullYear(),
        m: number | string = date.getMonth() + 1,
        d: number | string = '01',
        h: number | string = date.getHours(),
        i: number | string = date.getMinutes(),
        s: number | string = date.getSeconds();
    if (m < 10) {
        m = '0' + m;
    }
    if (h < 10) {
        h = '0' + h;
    }
    if (i < 10) {
        i = '0' + i;
    }
    if (s < 10) {
        s = '0' + s;
    }
    return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}


export function timestampToYesterDay(value: Date = new Date(), showTime = false) {
    let date = new Date(new Date().getTime()-(24*60*60*1000));
    let y: number = date.getFullYear(),
        m: number | string = date.getMonth() + 1,
        d: number | string = date.getDate(),
        h: number | string = date.getHours(),
        i: number | string = date.getMinutes(),
        s: number | string = date.getSeconds();
    if (m < 10) {
        m = '0' + m;
    }
    if (d < 10) {
        d = '0' + d;
    }
    if (h < 10) {
        h = '0' + h;
    }
    if (i < 10) {
        i = '0' + i;
    }
    if (s < 10) {
        s = '0' + s;
    }
    if (showTime) {
        return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
    } else {
        return y + '-' + m + '-' + d;
    }

}


/**
 * 时间戳转 yyyy年MM月dd日 星期x HH:mm:ss格式
 *
 * @param value
 * @returns {string}
 */
export function timestampToWeek(value = new Date(), showTime = false) {
    let date = new Date(value);
    let y: number = date.getFullYear(),
        m: number | string = date.getMonth() + 1,
        d: number | string = date.getDate(),
        h: number | string = date.getHours(),
        i: number | string = date.getMinutes(),
        s: number | string = date.getSeconds(),
        w: number | string = date.getDay();
    let week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
    if (m < 10) {
        m = '0' + m;
    }
    if (d < 10) {
        d = '0' + d;
    }
    if (h < 10) {
        h = '0' + h;
    }
    if (i < 10) {
        i = '0' + i;
    }
    if (s < 10) {
        s = '0' + s;
    }
    if (showTime) {
        return y + '年' + m + '月' + d + '日' + ' ' + week[w] + ' ' + ' ' + h + ':' + i + ':' + s;
    } else {
        return y + '年' + m + '月' + d + '日' + ' ' + week[w];
    }
}

/**
 * 时间戳转 yyyy年MM月dd日  HH时mm分ss秒格式
 *
 * @param value
 * @returns {string}
 */
export function timestampToDateCN(value:any = new Date(), showTime = false) {
    let date = new Date(value);
    let y: number = date.getFullYear(),
        m: number | string = date.getMonth() + 1,
        d: number | string = date.getDate(),
        h: number | string = date.getHours(),
        i: number | string = date.getMinutes(),
        s: number | string = date.getSeconds(),
        w: number | string = date.getDay();
    if (m < 10) {
        m = '0' + m;
    }
    if (d < 10) {
        d = '0' + d;
    }
    if (h < 10) {
        h = '0' + h;
    }
    if (i < 10) {
        i = '0' + i;
    }
    if (s < 10) {
        s = '0' + s;
    }
    if (showTime) {
        return y + '年' + m + '月' + d + '日' + ' ' + ' ' + h + '时' + i + '分' + s + '秒';
    } else {
        return y + '年' + m + '月' + d + '日';
    }
}
